<template>
  <div class="card-title">
    <div class="card-title_title">
      <span>
        <span class="iconfont icon-liuyanban-xian"></span>
        关于本站
      </span>
      <i></i>
    </div>
    <div class="website">
      <p class="website_time">本站已运行：{{ currentTimeHtml }}</p>
      <p><span class="iconfont icon-position-mark"></span> {{ userInfo.address }}</p>
      <p><span class="iconfont icon-youjian5"></span> {{ userInfo.mail }}</p>
      <p><span class="iconfont icon-icophone"></span> {{ userInfo.phone }}</p>
      <p>Copyright 2023 - 2033 © {{ userInfo.userName }}</p>
    </div>
  </div>
</template>
<script setup lang="ts">
import { getBloggerInfo } from '../service/api/Blogger'
let userInfo:any = ref({})
const currentTimeHtml = ref('')
const secondToDate = (second:any) => {
  if (!second) {
    return 0;
  }
  var time = new Array(0, 0, 0, 0, 0);
  if (second >= 365 * 24 * 3600) {
      time[0] = parseInt(second / (365 * 24 * 3600));
      second %= 365 * 24 * 3600;
  }
  if (second >= 24 * 3600) {
      time[1] = parseInt(second / (24 * 3600));
      second %= 24 * 3600;
  }
  if (second >= 3600) {
      time[2] = parseInt(second / 3600);
      second %= 3600;
  }
  if (second >= 60) {
      time[3] = parseInt(second / 60);
      second %= 60;
  }
  if (second > 0) {
      time[4] = second;
  }
  return time;
}
const setTime = () => {
  var create_time = Math.round(new Date(Date.UTC(2019, 9, 16, 0, 0, 0)).getTime() / 1000);
  var timestamp:any = Math.round((new Date().getTime() + 8 * 60 * 60 * 1000) / 1000);
  var currentTime:any = secondToDate((  timestamp-create_time));
  currentTimeHtml.value = currentTime[0] + '年' + currentTime[1] + '天'
      + currentTime[2] + '时' + currentTime[3] + '分' + currentTime[4]
      + '秒';
}

const getInfo = async () => {
  await nextTick()
  try {
    const res:any = await getBloggerInfo({})
    const data = res.data._value.data
    userInfo.value = data[0]
  } catch(err) {
    console.log(err)
  }
}
onMounted(() => {
  getInfo()
  setInterval(()=>{
    setTime()
  },1000)
})
</script>
<style scoped lang="scss">
.website{
    font-size: 14px;
    padding: 0 10px;
    p{
      text-align: left;
      line-height: 28px;
      margin-bottom: 10px;
    }
    &_time{
      font-size: 20;
      text-align: center;
      color: #00C675;
    }
  }
</style>